package work.utils;

import lombok.extern.java.Log;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;

@Log
public class TextUtils {

    //最长一百万个字符
    private static final int maxLen = 1000000;

    public static boolean textToClipboard(String text) {
        if (text == null) {
            log.warning("null无法复制到粘贴板");
            return false;
        }
        if (text.length() > maxLen) {
            log.warning("文本过长无法复制到粘贴板");
            return false;
        }
        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable tText = new StringSelection(text);
        clip.setContents(tText, null);
        log.info("文本已复制到粘贴板");
        return true;

    }


}
